package com.ruoyi.work.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.work.mapper.WorkSignatureMapper;
import com.ruoyi.work.domain.WorkSignature;
import com.ruoyi.work.service.IWorkSignatureService;

/**
 * 签名Service业务层处理
 *
 * @author fengcheng
 * @date 2025-03-18
 */
@Service
public class WorkSignatureServiceImpl implements IWorkSignatureService
{
    @Autowired
    private WorkSignatureMapper workSignatureMapper;

    /**
     * 查询签名
     *
     * @param signatureId 签名主键
     * @return 签名
     */
    @Override
    public WorkSignature selectWorkSignatureBySignatureId(Long signatureId)
    {
        return workSignatureMapper.selectWorkSignatureBySignatureId(signatureId);
    }

    /**
     * 查询签名列表
     *
     * @param workSignature 签名
     * @return 签名
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<WorkSignature> selectWorkSignatureList(WorkSignature workSignature)
    {
        return workSignatureMapper.selectWorkSignatureList(workSignature);
    }

    /**
     * 新增签名
     *
     * @param workSignature 签名
     * @return 结果
     */
    @Override
    public int insertWorkSignature(WorkSignature workSignature)
    {
        workSignature.setUserId(SecurityUtils.getUserId());
        workSignature.setDeptId(SecurityUtils.getDeptId());
        workSignature.setUserName(SecurityUtils.getUsername());
        workSignature.setDeptName(SecurityUtils.getLoginUser().getUser().getDept().getDeptName());
        workSignature.setCreateTime(DateUtils.getNowDate());
        return workSignatureMapper.insertWorkSignature(workSignature);
    }

    /**
     * 修改签名
     *
     * @param workSignature 签名
     * @return 结果
     */
    @Override
    public int updateWorkSignature(WorkSignature workSignature)
    {
        workSignature.setUpdateTime(DateUtils.getNowDate());
        return workSignatureMapper.updateWorkSignature(workSignature);
    }

    /**
     * 批量删除签名
     *
     * @param signatureIds 需要删除的签名主键
     * @return 结果
     */
    @Override
    public int deleteWorkSignatureBySignatureIds(Long[] signatureIds)
    {
        return workSignatureMapper.deleteWorkSignatureBySignatureIds(signatureIds);
    }

    /**
     * 删除签名信息
     *
     * @param signatureId 签名主键
     * @return 结果
     */
    @Override
    public int deleteWorkSignatureBySignatureId(Long signatureId)
    {
        return workSignatureMapper.deleteWorkSignatureBySignatureId(signatureId);
    }
}
